package com.meituan.catering.management.order.biz.model.converter;

import com.meituan.catering.management.common.model.api.http.AuditingHttpModel;
import com.meituan.catering.management.common.model.biz.AuditingBO;
import com.meituan.catering.management.common.model.biz.PageBO;
import com.meituan.catering.management.order.api.http.model.dto.CateringOrderPageHttpDTO;
import com.meituan.catering.management.order.api.http.model.enumeration.CateringOrderStatusEnum;
import com.meituan.catering.management.order.biz.model.CateringOrderBO;

import java.util.LinkedList;
import java.util.List;

/**
 * @author Believe
 * Date 2022/5/27 15:11
 */
public class CateringOrderPageHttpDTOCOnverter {

    public static CateringOrderPageHttpDTO toCateringOrderPageHttpDTO(PageBO<CateringOrderBO> pageBO){
        CateringOrderPageHttpDTO cateringOrderPageHttpDTO = new CateringOrderPageHttpDTO();
        cateringOrderPageHttpDTO.setPageIndex(pageBO.getPageIndex());
        cateringOrderPageHttpDTO.setPageSize(pageBO.getPageSize());
        cateringOrderPageHttpDTO.setTotalCount(pageBO.getTotalCount());
        cateringOrderPageHttpDTO.setTotalPageCount(pageBO.getTotalPageCount());
        cateringOrderPageHttpDTO.setRecords(toRecords(pageBO.getRecords()));
        return cateringOrderPageHttpDTO;
    }

    public static List<CateringOrderPageHttpDTO.Record> toRecords(List<CateringOrderBO> orderBOList){
        List<CateringOrderPageHttpDTO.Record> recordList = new LinkedList<>();
        for (CateringOrderBO cateringOrderBO : orderBOList) {
            CateringOrderPageHttpDTO.Record record = new CateringOrderPageHttpDTO.Record();
            record.setId(cateringOrderBO.getId());
            record.setTenantId(cateringOrderBO.getTenantId());
            record.setVersion(cateringOrderBO.getVersion());
            record.setAuditing(toAuditingHttpModel(cateringOrderBO.getAuditing()));
            record.setStatus(cateringOrderBO.getStatus());
            record.setTableNo(cateringOrderBO.getTableNo());
            record.setCustomerCount(cateringOrderBO.getCustomerCount());
            record.setTotalPrice(cateringOrderBO.getTotalPrice());
            record.setComment(cateringOrderBO.getComment());
            record.setShopSnapshotOnPlace(toShopSnapshot(cateringOrderBO.getId(),
                    cateringOrderBO.getShopBusinessNo(), cateringOrderBO.getShopNameOnPlace()));
            recordList.add(record);
        }
        return recordList;
    }


    public static AuditingHttpModel toAuditingHttpModel(AuditingBO auditingBO){
        AuditingHttpModel auditingHttpModel = new AuditingHttpModel();
        auditingHttpModel.setCreatedBy(auditingBO.getCreatedBy());
        auditingHttpModel.setCreatedAt(auditingBO.getCreatedAt());
        auditingHttpModel.setLastModifiedBy(auditingBO.getLastModifiedBy());
        auditingHttpModel.setLastModifiedAt(auditingBO.getLastModifiedAt());
        return auditingHttpModel;
    }

    public static CateringOrderPageHttpDTO.Record.ShopSnapshot toShopSnapshot(Long id, String shopBusinessNo, String shopNameOnPlace){
        CateringOrderPageHttpDTO.Record.ShopSnapshot shopSnapshot = new CateringOrderPageHttpDTO.Record.ShopSnapshot();
        shopSnapshot.setId(id);
        shopSnapshot.setBusinessNo(shopBusinessNo);
        shopSnapshot.setName(shopNameOnPlace);
        return shopSnapshot;
    }
}
